package com.cennavi.minenavidemo.activity.map;

import android.os.Bundle;
import android.text.TextUtils;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.cennavi.minenavidemo.R;
import com.cennavi.minenavidemo.utils.OkHttp3Utils;
import com.minedata.minenavi.SDKInitializer;
import com.minedata.minenavi.mapdal.BaseUrl;

public class TileActivity extends AppCompatActivity {
    TextView mTvData;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tile);
        mTvData = findViewById(R.id.data);
        getData();
    }

    private void getData() {

        new Thread(() -> {
            String url = BaseUrl.StyleUrl.replaceAll("\\\\", "/");

            if (!url.endsWith("/")) {
                url = url + "/";
            }

            if (!TextUtils.isEmpty(SDKInitializer.getApiKey())) {
                url = url + "map?key=1156128263&fields=gridId,gridData&appKey=" + SDKInitializer.getApiKey();
            } else {
                url = url + "map?key=1156128263&fields=gridId,gridData";
            }

            String result = OkHttp3Utils.getOkHttpString(url);

            mTvData.post(() -> {
                if (!TextUtils.isEmpty(result)) {
                    mTvData.setText(result);
                }
            });

        }).start();
    }
}
